//
//  UIBarButtonItem+Extension.m
//  赛拓
//
//  Created by 王磊 on 7/30/16.
//  Copyright © 2016 立金所. All rights reserved.
//

#import "UIBarButtonItem+Extension.h"

@implementation UIBarButtonItem (Extension)

+ (UIBarButtonItem *)itemLeftOffsetWithTarget:(id)target action:(SEL)action image:(NSString *)image highImage:(NSString *)highImage {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    // 设置图片
    UIImage *normalImage = [UIImage imageNamed:image];
    
    [btn setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];
    // 设置尺寸
    btn.k_size = CGSizeMake(normalImage.size.width, normalImage.size.height);
    
//    btn.imageEdgeInsets = UIEdgeInsetsMake(5, 0, 0, 0);
    
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
}

+ (UIBarButtonItem *)itemRightOffsetWithTarget:(id)target action:(SEL)action image:(NSString *)image highImage:(NSString *)highImage {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    // 设置图片
    UIImage *normalImage = [UIImage imageNamed:image];
    
    [btn setImage:normalImage forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];
    // 设置尺寸
    btn.k_size = CGSizeMake(30, 20);
    
//    btn.imageEdgeInsets = UIEdgeInsetsMake(5, 0, 0, 0);
    
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
}

+ (UIBarButtonItem *)itemRightOffsetWithTarget:(id)target action:(SEL)action title:(NSString *)title highTitle:(NSString *)highTitle {
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    // 设置图片
    
    [btn setTitle:title forState:UIControlStateNormal];
    
    [btn setTitle:highTitle forState:UIControlStateHighlighted];
    
    btn.titleLabel.font = [UIFont systemFontOfSize:15];
    
    [btn setTitleColor:ST_BLACK_COLOR forState:UIControlStateNormal];
    
    // 设置尺寸
    btn.k_size = CGSizeMake(40, 20);

    btn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
}

@end
